//
//  KTCoinDetailKLine.swift
//  KOLToken
//
//  Created by yangsan on 2020/3/15.
//  Copyright © 2020 iOS-team. All rights reserved.
//

import UIKit
import JXSegmentedView
class KTCoinDetailKLineView: UIView {
    // MARK: - property
    
    private var segmentedView = JXSegmentedView()
    private var segmentedDataSource = JXSegmentedTitleDataSource()
    private var controllerArray : [UIViewController] = []
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        buildUI()
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func buildUI() {
        segmentedView.delegate = self
        
        //配置数据源相关配置属性
        segmentedDataSource.titles = ["分时", "15分钟", "一小时", "日K", "三天", "指标"]
        segmentedDataSource.isTitleColorGradientEnabled = true
        //关联dataSource
        segmentedView.dataSource = self.segmentedDataSource
        let indicator = JXSegmentedIndicatorLineView()
        indicator.lineStyle = .lengthen
        //        indicator.indicatorColor = .blue
        segmentedView.indicators = [indicator]
//        segmentedView.listContainer =
//        addChartController()
        segmentedView.backgroundColor = .white
        addSubview(segmentedView)
    }
    
    func addChartController() {
        // 分时线
        let timeViewcontroller = KTChartViewController()
        timeViewcontroller.chartType = HSChartType.timeLineForDay
        controllerArray.append(timeViewcontroller)
        
        // 五日分时线
        let fiveDayTimeViewController = KTChartViewController()
        fiveDayTimeViewController.chartType = HSChartType.timeLineForFiveday
        controllerArray.append(fiveDayTimeViewController)
        
        // 日 K 线
        let kLineViewController = KTChartViewController()
        kLineViewController.chartType = HSChartType.kLineForDay
        controllerArray.append(kLineViewController)
        
        // 周 K 线
        let weeklyKLineViewController = KTChartViewController()
        weeklyKLineViewController.chartType = HSChartType.kLineForWeek
        controllerArray.append(weeklyKLineViewController)
        
        // 月 K 线
        let monthlyKLineViewController = KTChartViewController()
        monthlyKLineViewController.chartType = HSChartType.kLineForMonth
        controllerArray.append(monthlyKLineViewController)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        segmentedView.snp.makeConstraints { (make) in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(48)
        }
    }
}

extension KTCoinDetailKLineView : JXSegmentedViewDelegate {
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        
    }
    // 点击选中的情况才会调用该方法
    func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
        
    }
    // 滚动选中的情况才会调用该方法
    func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {
        
    }
    // 正在滚动中的回调
    func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
        
    }
}
